package com.tedu.movie.controller;

import com.tedu.movie.pojo.Item;
import com.tedu.movie.pojo.ItemCategoryVO;
import com.tedu.movie.pojo.ServerResult;
import com.tedu.movie.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@CrossOrigin
@RestController
public class ItemController {
    @Autowired
    ItemService itemService;

    @RequestMapping("/item/updateItem")
    public ServerResult updateItem(Item item){
        boolean isSuccess = itemService.updateItem(item);
        if(isSuccess){
            return new ServerResult(0,"更新成功",null);
        }else {return new ServerResult(1,"更新失败",null);}

    }
    @RequestMapping("/item/deleteItem")
    public ServerResult deleteItem(Integer id){
        boolean isSuccess = itemService.deleteItem(id);
        if(isSuccess){
            return new ServerResult(0,"删除成功",null);
        }else {return new ServerResult(1,"删除失败",null);}
    }

    @RequestMapping("/item/selectAll")
    public ServerResult selectAll(){
        List<ItemCategoryVO> list = itemService.selectAll();
        return new ServerResult(0,"查询成功",list);

    }
    @RequestMapping("/item/insertItem")
    public  ServerResult insertItem(Item item){
        boolean isSuccess = itemService.insertItem(item);
        if(isSuccess){
            return new ServerResult(0,"添加成功",null);
        }else{
            return new ServerResult(1,"添加失败",null);
        }
    }

    @RequestMapping("/item/selectById")
    public ServerResult selectById(Integer id){
        Item item = itemService.selectById(id);
        return new ServerResult(0,"查询成功",item);
    }

    @RequestMapping("/item/selectByCategoryId")
    public ServerResult selectByCategoryId(Integer categoryId){
        List<Item> list = itemService.selectByCategoryId(categoryId);
        return new ServerResult(0,"查询成功",list);
        //http://localhost:2022/swagger-ui.html
    }
}